import java.net.{ URI, URL, URLEncoder }
import java.nio.charset.{ Charset, StandardCharsets }
import java.util.Locale

import org.apache.http.Consts
import org.apache.http.client.utils.{ URIBuilder, URIUtils, URLEncodedUtils }
import org.apache.http.util.{ Args, TextUtils }
import play.utils.UriEncoding

import scala.collection.JavaConverters._

object Test1234 {

  def main(arr: Array[String]): Unit = {
    println("11" * 10)
    val aa = """http://www.hsredcross.org.cn/bigclass.asp?bname=红十字会简介"""
    val uri = URI.create(aa)
    val builder = new URIBuilder(uri)
    val query = builder.setCustomQuery(uri.getRawQuery)
    builder.setCharset(Charset.forName("gb2312"))
    println(query.toString)
    println("11" * 10)

    /*println(rewriteURI(new URI(aa)))
    println(new URIBuilder(rewriteURI(new URI(aa)))
      //.setPort(url.getPort)
      //.setPath(url.getPath)
      //.setCustomQuery(url.getQuery)
      .setCharset(Charset.forName("gb2312")).toString)
    println(URLEncodedUtils.format(URLEncodedUtils.parse(aa, Charset.forName("utf-8")), "utf-8"))*/
  }
  /*def rewriteURI(uri: URI): URI = {
    Args.notNull(uri, "URI")
    if (uri.isOpaque) return uri
    val uribuilder = new URIBuilder(uri)
    if (uribuilder.getUserInfo != null) uribuilder.setUserInfo(null)
    if (TextUtils.isEmpty(uribuilder.getPath)) uribuilder.setPath("/")
    if (uribuilder.getHost != null) uribuilder.setHost(uribuilder.getHost.toLowerCase(Locale.ROOT))
    uribuilder.setFragment(null)
    uribuilder.setCharset(Charset.forName("gb2312"))
    uribuilder.build
  }*/
}
